﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightTimer
{
    public partial class MainPage : UserControl
    {
        #region contructors
        public MainPage()
        {
            InitializeComponent();
        }

        public MainPage(IDictionary<String, String> parameters)
            : this()
        {
            if (parameters.ContainsKey("EventTime"))
            {
                try
                {
                    EventTime = DateTime.Parse(parameters["EventTime"]);
                }
                catch (Exception) { }
            }
            if (parameters.ContainsKey("EventDescription"))
            {
                try
                {
                    EventDescription = parameters["EventDescription"];
                }
                catch (Exception) { }
            }
            if (parameters.ContainsKey("EventTimeUrl"))
            {
                try
                {
                    EventTimeUrl = parameters["EventTimeUrl"];
                }
                catch (Exception) { }
            }
            if (parameters.ContainsKey("EventTimeCache"))
            {
                try
                {
                    EventTimeCache = Boolean.Parse(parameters["EventTimeCache"]);
                }
                catch (Exception) { }
            }
            if (parameters.ContainsKey("EventTimeCacheDuration"))
            {
                try
                {
                    EventTimeCacheDuration = Int32.Parse(parameters["EventTimeCacheDuration"]);
                }
                catch (Exception) { }
            }
            if (parameters.ContainsKey("Tooltip"))
            {
                try
                {
                    Tooltip = parameters["Tooltip"];
                }
                catch (Exception) { }
            }

        }
        #endregion

        /// <summary>
        /// Properties used when you set values from html code.
        /// </summary>
        #region Properties
        public DateTime EventTime
        {
            set
            {
                myCounter.EventTime = value;
            }
        }

        public String EventDescription
        {
            set
            {
                myCounter.EventDescription = value;
            }
        }

        public Boolean EventTimeCache
        {
            set
            {
                myCounter.EventTimeCache = value;
            }
        }

        public int EventTimeCacheDuration
        {
            set
            {
                myCounter.EventTimeCacheDuration = value;
            }
        }

        public String EventTimeUrl
        {
            set
            {
                myCounter.EventTimeUrl = value;
            }
        }

        public String Tooltip
        {
            set
            {
                myCounter.Tooltip = value;
            }
        }
        #endregion

        #region Methods
        private void myControl_CounterFinish(object sender, EventArgs e)
        {
            // This code is invoked when counter stop counting.
        }
        #endregion
    }
}
